/*
 * Delivery.java
 *
 * Created on 27 March 2007, 12:09
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package usyd.comp5348;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity class Delivery
 *
 * @author Yuezhong Zhang
 */
@Entity(name="Delivery")
public class Delivery implements Serializable {
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO, generator="DelIdSeq")
    @SequenceGenerator(name="DelIdSeq", sequenceName="del_id_seq")
    private Integer id;
    
    /** Creates a new instance of Delivery */
    public Delivery() {
    }
    
    public Delivery(DeliveryInfo d) {
        setDate(d.getDeliveryDate());
        if (d.getId() != DeliveryInfo.UNDEFINED)
            setId(d.getId());
        setOrderId(d.getOrderId());
        setStatus(d.getStatus());
        setWarehouse(d.getWarehouse());
        setShop(d.getShop());
    }
    
    public DeliveryInfo getDeliveryInfo() {
        return new DeliveryInfo(getId(), getOrderId(), getWarehouse(), getDate(), getStatus(), getShop());
    }
    
    /**
     * Gets the id of this Delivery.
     * @return the id
     */
    public Integer getId() {
        return this.id;
    }
    
    /**
     * Sets the id of this Delivery to the specified value.
     * @param id the new id
     */
    public void setId(Integer id) {
        this.id = id;
    }
    
    /**
     * Returns a hash code value for the object.  This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }
    
    /**
     * Determines whether another object is equal to this Delivery.  The result is
     * <code>true</code> if and only if the argument is not null and is a Delivery object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Delivery)) {
            return false;
        }
        Delivery other = (Delivery)object;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
        return true;
    }
    
    /**
     * Returns a string representation of the object.  This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "usyd.comp5348.entity.Delivery[id=" + id + "]";
    }
    
    /**
     * Holds value of property orderId.
     */
    @Column(name="order_id",nullable=false)
    private int orderId;
    
    /**
     * Getter for property orderId.
     * @return Value of property orderId.
     */
    public int getOrderId() {
        return this.orderId;
    }
    
    /**
     * Setter for property orderId.
     * @param orderId New value of property orderId.
     */
    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }
    
    /**
     * Holds value of property warehouse.
     */
    @Column(name="warehouse",length=16,nullable=false)
    private String warehouse;
    
    /**
     * Getter for property warehouse.
     * @return Value of property warehouse.
     */
    public String getWarehouse() {
        return this.warehouse;
    }
    
    /**
     * Setter for property warehouse.
     * @param warehouse New value of property warehouse.
     */
    public void setWarehouse(String warehouse) {
        this.warehouse = warehouse;
    }
    
    /**
     * Holds value of property shop.
     */
    @Column(name="shop",length=16,nullable=false)
    private String shop;
    
    /**
     * Getter for property warehouse.
     * @return Value of property warehouse.
     */
    public String getShop() {
        return this.shop;
    }
    
    /**
     * Setter for property warehouse.
     * @param warehouse New value of property warehouse.
     */
    public void setShop(String shop) {
        this.shop = shop;
    }
    
    /**
     * Holds value of property date.
     */
    @Column(name="delivery_date",nullable=false)
    @Temporal(value = TemporalType.DATE)
    private Date date;
    
    /**
     * Getter for property date.
     * @return Value of property date.
     */
    public Date getDate() {
        return this.date;
    }
    
    /**
     * Setter for property date.
     * @param date New value of property date.
     */
    public void setDate(Date date) {
        this.date = date;
    }
    
    /**
     * Holds value of property status.
     */
    @Column(name="status", nullable =false)
    private int status;
    
    /**
     * Getter for property status.
     * @return Value of property status.
     */
    public int getStatus() {
        return this.status;
    }
    
    /**
     * Setter for property status.
     * @param status New value of property status.
     */
    public void setStatus(int status) {
        this.status = status;
    }
    
}
